﻿@{
    Layout = "_LayoutAdmin";
}

@model IReadOnlyList<Moonglade.Model.CustomPageMetaData>

@section scripts{
    <script>
        $(function () {
            $(".btn-delete").click(function () {
                var cfm = confirm("Delete Confirmation?");
                if (cfm) {
                    deletePage($(this).data("pageid"), $(this).data("routename"));
                }
            });
        });

        function deletePage(pageid, routename) {
            $("#span-processing-" + pageid).show();
            ajaxPostWithCSRFToken("manage/delete", { pageid: pageid, routename: routename }, function (data) {
                $("#tr-" + data).hide();
            });
        }
    </script>
}

<h3>
    Pages
    <a class="btn btn-outline-success float-right" asp-controller="CustomPage" asp-action="Create">
        <span class="icon-plus"></span>
        New
    </a>
</h3>
<hr />


@if (Model.Any())
{
    @Html.AntiForgeryToken()

    <table id="pages-table" class="table table-bordered">
        <thead>
            <tr>
                <th>Title</th>
                <th>Route Name</th>
                <th class="table-item-w20">Created</th>
                <th class="table-item-w20">Options</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var customPage in Model.OrderByDescending(p => p.CreateOnUtc))
            {
                <tr id="tr-@customPage.Id">
                    <td>@customPage.Title</td>
                    <td>@customPage.RouteName</td>
                    <td data-sort="@customPage.CreateOnUtc.ToString("yyyyMMddHHmmss")">
                        @customPage.CreateOnUtc
                    </td>
                    <td>
                        <a class="btn btn-primary btn-sm btn-edit" asp-controller="CustomPage" asp-action="Edit" asp-route-id="@customPage.Id">
                            Edit
                        </a>
                        <a class="btn btn-danger btn-sm btn-delete" data-pageid="@customPage.Id" data-routename="@customPage.RouteName" href="javascript:;">
                            Delete
                        </a>
                        <span id="span-processing-@customPage.Id" style="display: none">...</span>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
else
{
    <div class="empty-recycle">
        <div class="text-center">
            <h4>No Pages</h4>
            <p class="text-muted">no items to show</p>
        </div>
    </div>
}